import * as Mockdata from './mockdata'
import { clear } from './sightsee'
class Flyverify {
  constructor() {
    this.timer = null
  }
  //添加滑翔伞
  async addHxs(air) {
    let m = {
      id: air.snId, //maker唯一标识
      coordinate: [Number(air.latitude), Number(air.longitude), air.height], //坐标位置
      coordinateType: 0, //坐标系类型
      imagePath:
        air.uavType === 1
          ? window.origin + '/poi/文旅观光@2x.png'
          : air.uavType === 2
            ? window.origin + '/poi/poi_人员@2x.png'
            : window.origin + `/poi/qjss_lenged_02.png`, //图片路径
      anchors: [-25, 50],
      imageSize: [50, 50],
      fixedSize: true,
      text: `类型：${air.uavType === 1 ? '滑翔伞' : air.uavType === 2 ? 'Evtol' : '直升机'}\n高度：${air.height}m\n速度：${air.gs}m/s`,
      fontColor: '#ffffff',
      fontSize: 14,
      textBackgroundColor: '#008214',
      range: [0, 2000000000], //标签的可见范围 [Min,Max]
      autoHidePopupWindow: true,
      groupId: 'wrjMarker',
      displayMode: 2, //显示模式
      autoHeight: false,
      occlusionCull: false
    }
    let o = {
      id: air.snId,
      groupId: 'hxs',
      pakFilePath: HostConfig.PakPathWrj, //资源库pak文件路径,推荐使用cloud内置的文件资源管理器加载pak并使用@path方式传入参数
      assetPath: '/JC_CustomAssets/ObjectLibrary/Exhibition/滑翔伞/滑翔伞带人', //资源目录，自定义对象在pak文件资源包里的相对路径
      location: [Number(air.latitude), Number(air.longitude), air.height], //位置坐标
      coordinateType: 0, // 坐标系类型
      rotation: [0, 0, 0], // 世界坐标系旋转
      localRotation: [0, 90, 0], //模型自身旋转
      scale: [5, 5, 5], //模型缩放
      smoothMotion: 1, //1: 平滑移动，0: 跳跃移动
      supportAttach: true //不支持贴画贴合
    }
    if (air.uavType == 2) {
      //Evtol模型
      o.assetPath = '/JC_CustomAssets/ObjectLibrary/Exhibition/盐田低空无人机/无人机3'
      o.localRotation = [0, -90, 0]
    }
    if (air.uavType == 3) {
      //直升机模型
      o.assetPath = '/JC_CustomAssets/ObjectLibrary/Exhibition/交通工具/飞机/直升机_1'
    }
    await __g.customObject.add(o)
    await __g.marker.add(m)
    await __g.marker.add(m)
    await __g.marker.setAttachCustomObject([
      {
        markerId: m.id, //标注id
        objectId: o.id, //自定义对象id
        offset: [0, 0, 0] //偏移量
      }
    ])
    __g.customObject.callBPFunction([
      {
        id: o.id,
        functionName: '状态',
        parameters: [
          { paramType: 0, paramValue: 1 },
          { paramType: 3, paramValue: 2 }
        ]
      }
    ])
  }

  startAnimation() {
    let i = 0
    this.addHxs(Mockdata.HXS01[0])
    // this.addHxs(Mockdata.HXS02[0])
    this.addHxs(Mockdata.Evtol01[0])
    // this.addHxs(Mockdata.Evtol02[0])
    this.addHxs(Mockdata.ZSJ01[0])
    clearInterval(this.timer)
    this.timer = setInterval(() => {
      i++
      if (i == Mockdata.HXS01.length) {
        i = 0
      }
      __g.customObject.setLocation(
        Mockdata.HXS01[i].snId,
        [
          Number(Mockdata.HXS01[i].latitude),
          Number(Mockdata.HXS01[i].longitude),
          Mockdata.HXS01[i].height
        ],
        10
      )
      __g.customObject.setLocation(
        Mockdata.HXS02[i].snId,
        [
          Number(Mockdata.HXS02[i].latitude),
          Number(Mockdata.HXS02[i].longitude),
          Mockdata.HXS02[i].height
        ],
        10
      )
      __g.customObject.setLocation(
        Mockdata.Evtol01[i].snId,
        [
          Number(Mockdata.Evtol01[i].latitude),
          Number(Mockdata.Evtol01[i].longitude),
          Mockdata.Evtol01[i].height
        ],
        10
      )
      __g.customObject.setLocation(
        Mockdata.Evtol02[i].snId,
        [
          Number(Mockdata.Evtol02[i].latitude),
          Number(Mockdata.Evtol02[i].longitude),
          Mockdata.Evtol02[i].height
        ],
        10
      )
      __g.customObject.setLocation(
        Mockdata.ZSJ01[i].snId,
        [
          Number(Mockdata.ZSJ01[i].latitude),
          Number(Mockdata.ZSJ01[i].longitude),
          Mockdata.ZSJ01[i].height
        ],
        10
      )

      __g.marker.update({
        id: Mockdata.ZSJ01[i].snId,
        imagePath: window.origin + `/poi/qjss_lenged_02.png`, //图片路径
        text: `类型：直升机\n高度：${Mockdata.ZSJ01[i].height}m\n速度：${Mockdata.ZSJ01[i].gs}m/s`,
        textBackgroundColor: Mockdata.ZSJ01[i].height < 400 ? '#ff0000' : '#008214'
      })

      __g.marker.update({
        id: Mockdata.HXS01[i].snId,
        imagePath: window.origin + '/poi/文旅观光@2x.png', //图片路径
        text: `类型：滑翔伞\n高度：${Mockdata.HXS01[i].height}m\n速度：${Mockdata.HXS01[i].gs}m/s`
      })
      // 变色
      __g.marker.update({
        id: Mockdata.HXS02[i].snId,
        imagePath: window.origin + '/poi/文旅观光@2x.png', //图片路径
        text: `类型：滑翔伞\n高度：${Mockdata.HXS02[i].height}m\n速度：${Mockdata.HXS02[i].gs}m/s`,
        textBackgroundColor: Mockdata.HXS02[i].height > 300 ? '#ff0000' : '#008214'
      })

      __g.marker.update({
        id: Mockdata.Evtol01[i].snId,
        imagePath: window.origin + '/poi/poi_人员@2x.png', //图片路径
        text: `类型：eVTOL\n高度：${Mockdata.Evtol01[i].height}m\n速度：${Mockdata.Evtol01[i].gs}m/s`
      })
      // 变色
      __g.marker.update({
        id: Mockdata.Evtol02[i].snId,
        imagePath: window.origin + '/poi/poi_人员@2x.png', //图片路径
        text: `类型：eVTOL\n高度：${Mockdata.Evtol02[i].height}m\n速度：${Mockdata.Evtol02[i].gs}m/s`,
        textBackgroundColor: Mockdata.Evtol02[i].height > 120 ? '#ff0000' : '#008214'
      })
    }, 1000)
  }

  clear() {
    clearInterval(this.timer)
    this.timer = null
    __g.customObject.clear()
  }
}

export default Flyverify
